<template>
  <div>
    <el-card class="box-card">
      <!--  -->
      <el-table :data="tableData"
                v-loading="loading"
                style="width: 100%"
                :header-cell-style="{background:'#f8f8f9'}">

        <el-table-column label="类型"
                         prop="ty">
          <template slot-scope="scope">
            <span>{{scope.row.ty==1?'公众号上墙':'平台首页上墙'}}</span>
          </template>
        </el-table-column>
        <el-table-column label="用户id"
                         prop="uid">
        </el-table-column>
        <el-table-column label="用户昵称"
                         prop="comUser.nickName">
        </el-table-column>
        <el-table-column label="用户姓名"
                         prop="comUser.realName">
        </el-table-column>
        <el-table-column label="用户电话"
                         prop="comUser.phone">
        </el-table-column>
        <el-table-column label="申请时间"
                         prop="createTime">
        </el-table-column>
        <el-table-column label="备注"
                         prop="remark">
        </el-table-column>

        <el-table-column label="操作">
          <template v-slot="data">
            <el-button icon="el-icon-edit"
                       type="text"
                       @click="updateHandler(data.row.id)">修改</el-button>
            <el-button icon="el-icon-delete"
                       type="text"
                       @click="deleteHandler(data.row.id)">删除</el-button>
          </template>

        </el-table-column>
      </el-table>
      <div class="page"
           v-show="total!=0">
        <el-pagination background
                       @size-change="handleSizeChange"
                       @current-change="handleCurrentChange"
                       :current-page="queryParams.pageNum"
                       :page-sizes="[3, 5, 7, 9]"
                       :page-size="queryParams.pageSize"
                       layout="total, sizes, prev, pager, next, jumper"
                       :total="total">
        </el-pagination>
      </div>
    </el-card>

    <div>
      <el-dialog title="修改相亲工具箱"
                 :visible.sync="dialogVisible"
                 width="30%">
        <el-form :model="formData"
                 :rules="rules"
                 ref="ruleForm"
                 label-width="80px">
          <el-form-item label="备注"
                        prop="remark">
            <el-input v-model="formData.remark"
                      placeholder="请输入名字名称"></el-input>
          </el-form-item>

        </el-form>
        <span slot="footer"
              class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary"
                     @click="update">确 定</el-button>
        </span>
      </el-dialog>
    </div>

  </div>

</template>

<script>
export default {
  data() {
    return {
      loading: false,
      tableData: [],
      formData: { comUser: null, createBy: null, createTime: null, id: null, params: {}, remark: null, searchValue: null, ty: 2, uid: 69, updateBy: null, updateTime: null },
      queryParams: { pageNum: 1, pageSize: 5 },
      total: 0,
      rules: {
        remark: [{ required: true, message: '请输入备注', trigger: 'blur' }]
      },
      dialogVisible: false
    }
  },
  methods: {
    async getTableList() {
      let { data } = await this.$axios.get('com/gjx/list', { params: this.queryParams })
      console.log(data)
      this.tableData = data.rows
      this.total = data.total
      this.loading = false
    },
    handleSizeChange(val) {
      this.queryParams.pageSize = val
      this.getTableList()
    },
    handleCurrentChange(val) {
      this.queryParams.pageNum = val
      this.getTableList()
    },
    deleteHandler(id) {
      this.$confirm(`是否确认删除id为?${id}的数据项`, '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          let { data } = await this.$axios.delete(`com/gjx/${id}`)
          if (data.code == 200) {
            this.$message({ type: 'success', message: data.msg })
            this.getTableList()
          }
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    async updateHandler(id) {
      let { data } = await this.$axios.get(`com/gjx/${id}`)
      console.log(data)
      this.dialogVisible = true
      this.formData = data.data
    },
    async update() {
      let { data } = await this.$axios.put(`com/gjx`, this.formData)
      if (data.code != 200) return this.$message.error(data.msg)
      this.$message({ type: 'success', message: data.msg })
      this.dialogVisible = false
      this.getTableList()
    }
  },
  mounted() {
    this.getTableList()
  }
}
</script>

<style>
</style>